import request from './Request'

/**
 * 登录
 * @param obj
 * @returns {Promise<AxiosResponse<any>>}
 */
const login = (obj) => {
  return request({
    method: 'post',
    url: '/login',
    data: obj,
    showLoading: false
  })
}
/**
 * 获取验证码
 * @returns {Promise<AxiosResponse<any>>}
 */
const captcha = () => {
  return request({
    method: 'get',
    url: '/captcha',
    showLoading: true
  })
}

/**
 * 注册
 * @param obj
 * @returns {Promise<AxiosResponse<any>>}
 */
const register = (obj) => {
  return request({
    method: 'post',
    url: '/register',
    data: obj,
    showLoading: true
  })
}
/**
 * 重置密码
 * @param obj
 * @returns {Promise<AxiosResponse<any>>}
 */
const resetPassword = (obj) => {
  return request({
    method: 'post',
    url: '/resetPassword',
    data: obj,
    showLoading: true
  })
}
/**
 * 获取联系人
 * @returns {Promise<AxiosResponse<any>>}
 */
const getContactList = (userId) => {
  return request({
    method: 'post',
    url: '/contact/contactList',
    data: {
      userId: userId
    },
    showLoading: false
  })
}
/**
 * 获取用户信息
 * @param arg
 * @returns {*}
 */
const getUser = (arg) => {
  return request({
    method: 'post',
    url: '/getUserInfo',
    data: {
      id: arg
    },
    showLoading: false
  })
}
/**
 * 上传头像
 * @param arg
 * @returns {*}
 */
const uploadAvatar = (arg) => {
  return request({
    method: 'post',
    url: '/file/avatar',
    data: arg,
    uploadFile: true,
    showLoading: false
  })
}
/**
 * 修改用户信息
 * @param arg
 * @returns {*}
 */
const updateUserInfo = (arg) => {
  return request({
    method: 'post',
    url: '/updateUserInfo',
    data: arg,
    showLoading: false
  })
}
/**
 * 发送消息
 * @param arg
 * @returns {*}
 */
const sendMessage = (arg) => {
  return request({
    method: 'post',
    url: '/chat/sendMessage',
    data: arg,
    showLoading: false
  })
}
/**
 * 发送文件消息
 * @param arg
 * @returns {*}
 */
const sendFileMessage = (arg) => {
  return request({
    method: 'post',
    url: '/chat/sendFileMessage',
    data: arg,
    uploadFile: true,
    showLoading: false
  })
}
/**
 * 添加联系人  发送好友添加申请
 * @param arg
 * @returns {*}
 */
const addContact = (arg) => {
  return request({
    method: 'post',
    url: '/contact/addContact',
    data: arg,
    showLoading: false
  })
}
/**
 * 保存联系人申请  好友申请消息接收过后 保存在数据库
 * @param arg
 * @returns {*}
 */
const savaContactApply = (arg) => {
  return request({
    method: 'post',
    url: '/contact/saveContactApply',
    data: arg,
    showLoading: false
  })
}
/**
 * 获取联系人申请列表
 * @param userId
 * @returns {*}
 */
const getContactApply = (userId) => {
  return request({
    method: 'get',
    url: '/contact/contactApply',
    params: {
      userId: userId
    },
    showLoading: false
  })
}
/**
 * 删除联系人申请
 * @param contactApplyId
 * @param userId
 * @returns {*}
 */
const deleteContactApply = (contactApplyId, userId) => {
  return request({
    method: 'post',
    url: '/contact/deleteContactApply',
    params: {
      contactApplyId: contactApplyId,
      userId: userId
    },
    showLoading: false
  })
}
/**
 * 接受联系人申请
 * @param arg
 * @returns {*}
 */
const acceptApply = (arg) => {
  return request({
    method: 'post',
    url: '/contact/acceptApply',
    data: arg,
    showLoading: false
  })
}
/**
 * 更新联系人申请
 * @param userId
 * @returns {*}
 */
const updateContactApply = (userId) => {
  return request({
    method: 'post',
    url: '/contact/updateContactApply',
    params: {
      userId: userId
    },
    showLoading: false
  })
}
/**
 * 更新联系人备注
 * @param arg
 * @returns {*}
 */
const updateContactNoteName = (arg) => {
  return request({
    method: 'post',
    url: '/contact/updateContactNoteName',
    data: arg,
    showLoading: false
  })
}
/**
 * 更新用户 sweetCircleId
 * @param arg
 * @returns {*}
 */
const updateUserSweetCircleId = (arg) => {
  return request({
    method: 'post',
    url: '/updateUserSweetCircleId',
    data: arg,
    showLoading: false
  })
}
/**
 * 更新联系人信息
 * @param arg
 * @returns {*}
 */
const updateContactInfo = (arg) => {
  return request({
    method: 'post',
    url: '/contact/updateContactInfo/sweetCircleAuth',
    data: arg,
    showLoading: false
  })
}
/**
 * 加入黑名单
 * @param arg
 * @returns {*}
 */
const joinInBlacklist = (arg) => {
  return request({
    method: 'post',
    url: '/contact/joinInBlacklist',
    data: arg,
    showLoading: false
  })
}
/**
 * 删除联系人
 * @param arg
 * @returns {*}
 */
const deleteContact = (arg) => {
  return request({
    method: 'post',
    url: '/contact/deleteContact',
    data: arg,
    showLoading: false
  })
}
/**
 * 移除黑名单
 * @param arg
 * @returns {*}
 */
const removeBlacklist = (arg) => {
  return request({
    method: 'post',
    url: '/contact/removeBlacklist',
    data: arg,
    showLoading: false
  })
}
/**
 * 获取离线消息
 * @param arg
 * @returns {*}
 */
const getOfflineMessage = (arg) => {
  return request({
    method: 'get',
    url: '/chat/getOfflineMessage',
    params: arg,
    showLoading: false
  })
}

/**
 * 删除会话  删除所有消息记录
 * @param sessionId {sessionId}
 * @returns {*}
 */
const deleteMessage = (sessionId) => {
  return request({
    method: 'post',
    url: '/chat/deleteMessage',
    data: {
      sessionId: sessionId
    },
    showLoading: false
  })
}

export default {
  captcha,
  login,
  register,
  resetPassword,
  getContactList,
  getUser,
  uploadAvatar,
  updateUserInfo,
  sendMessage,
  sendFileMessage,
  addContact,
  savaContactApply,
  getContactApply,
  deleteContactApply,
  acceptApply,
  updateContactApply,
  updateContactNoteName,
  updateUserSweetCircleId,
  updateContactInfo,
  joinInBlacklist,
  deleteContact,
  removeBlacklist,
  getOfflineMessage,
  deleteMessage
}
